package flc.ast.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.TimeZone;

import flc.ast.R;
import flc.ast.bean.MyTimerBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class TimerAdapter extends StkProviderMultiAdapter<MyTimerBean> {

    public TimerAdapter() {
        addItemProvider(new StkSingleSpanProvider(30));
        addItemProvider(new TimerProvider());
    }

    private class TimerProvider extends BaseItemProvider<MyTimerBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_timer;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyTimerBean bean) {
            long time = bean.getHour() * 60 * 60 * 1000L + bean.getMinute() * 60 * 1000L + bean.getSecond() * 1000L;
            SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            baseViewHolder.setText(R.id.tvTimerItemTime, TimeUtils.millis2String(time, format));
            baseViewHolder.setText(R.id.tvTimerItemTimeChinese, bean.getHour() + getContext().getString(R.string.hour_text) + bean.getMinute() + getContext().getString(R.string.minute_text) + bean.getSecond() + getContext().getString(R.string.second_text));
        }
    }
}
